/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.dao;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;

import com.thinkgem.jeesite.common.persistence.BaseDao;
import com.thinkgem.jeesite.common.persistence.BaseDaoImpl;
import com.boxin.ims.modules.wechat.entity.RecommendConfig;

/**
 * 三级推广配置文件DAO接口
 * @author zhangshanshan
 * @version 2016-03-14
 */
public interface RecommendConfigDao extends RecommendConfigDaoCustom, CrudRepository<RecommendConfig, Long> {

	@Modifying
	@Query("delete from  RecommendConfig   where id = ?1")
	public int deleteById(Long id);
	
	@Query("from RecommendConfig   where userId = ?1 and isOpen = '1' ")
	public RecommendConfig getByUserId(Long userId);
	
	/** 根据userId将活动关闭  */
	@Modifying
	@Query(" update  RecommendConfig  set isOpen = '0'   where userId = ?1")
	public int closeAllByUserId(Long userId);
		
	/** 根据id将活动开启  */
	@Modifying
	@Query(" update  RecommendConfig  set isOpen = '1'   where id = ?1")
	public int openRecommendConfigById(Long id) ;
	
}

/**
 * DAO自定义接口
 * @author zhangshanshan
 */
interface RecommendConfigDaoCustom extends BaseDao<RecommendConfig> {

}

/**
 * DAO自定义接口实现
 * @author zhangshanshan
 */
@Component
class RecommendConfigDaoImpl extends BaseDaoImpl<RecommendConfig> implements RecommendConfigDaoCustom {

}
